package com.xyd.Service;

import com.xyd.bean.Product;
import com.xyd.bean.ShoppingCar;
import com.xyd.dao.ShoppingCarMapper;
import com.xyd.util.SqlSessionFactoryUtil;
import org.apache.ibatis.session.SqlSession;

import java.util.List;

public class ShoppingCarService {
    SqlSession sqlSession = SqlSessionFactoryUtil.getSqlSession();
    ShoppingCarMapper shoppingCarMapper = sqlSession.getMapper(ShoppingCarMapper.class);

    public ShoppingCar getShoppingCarById(int id) {
        return shoppingCarMapper.getShoppingCarById(id);
    }

    public List<ShoppingCar> getShoppingCarByUid(int uid) {
        return shoppingCarMapper.getShoppingCarByUid(uid);
    }

    //将商品添加到购物车
    public void addSoppingCar(ShoppingCar shoppingCar) {
        shoppingCarMapper.addSoppingCar(shoppingCar);
        sqlSession.commit();
    }

    public int updataShoppingCarById(ShoppingCar shoppingCar) {
        return shoppingCarMapper.updataShoppingCarById(shoppingCar);
    }

    public List<ShoppingCar> getAllShoppingCar() {
        return shoppingCarMapper.getAllShoppingCar();
    }

    public int delShoppingCarById(int id) {
        return shoppingCarMapper.delShoppingById(id);
    }
}
